package com.zhoukun.cloud.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.apache.http.protocol.HTTP;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author zhoukun 86547462@qq.com
 * @version 1.0
 * @date 2020/10/28 20:37
 */
@Component
@Slf4j
/**
 * GlobalFilter全局功能，判断是否存在uname
 */
public class MyLogGlobalFilters implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("custom global filter");
//        String uname= exchange.getRequest().getQueryParams().getFirst("uname");
//        if(uname==null)
//        {
//            log.info("用户名不能为空。。。");
//            exchange.getResponse().setRawStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);//设置状态码405
//            return exchange.getResponse().setComplete();
//        }
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
